var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var cors = require('cors')
var system = require('./routes/system');
var upload = require('./routes//common/upload');
var myCenter = require('./routes/myCenter/index');
var dictionaryService = require('./routes/dictionaryService/dictionaryService');
var connect = require('./database/connect') //连接数据库
var {job}=require('./utils/schedule')//定时任务
var wsServer2 = require('./routes/system/wsServer/server');
var { checkToken } = require('./utils/authToken')
var STATIC=require('./static/constant')
global.STATIC=STATIC
const { createProxyMiddleware } = require("http-proxy-middleware")
var app = express();
app.use('/api', createProxyMiddleware({
  target: 'https://localhost:12580'
}))
app.use(cors({
  origin: 'http://localhost:12580',
})) //处理跨域
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

/*
 const midAdwather=(req,res,next)=>{ //全局中间件 第二种 写个函数 然后写进路由去
  checkToken(req,res,next)
}
 
 app.use('/XXXX',midAdwather,indexRouter) //全局中间件 第二种 写个函数 然后写进路由去
 */
// app.use('/',(req,res,next)=>{//全局中间件
//   checkToken(req,res,next) //后端验证token的中间件函数
// }, indexRouter);
app.use(system);//系统信息接口
app.use('/my', (req, res, next) => {//我的中心接口
  checkToken(req, res, next)
}, myCenter);
// app.use('/auth', authRouter);  //token验证接口
app.use('/common', upload);//上传组件接口
app.use('/dictionaryService', dictionaryService);

module.exports = app;
//console.log("")
